import request from '@/utils/request'

/**
 * 获取优惠券管理列表
 * @param {*} params
 * @returns
 */
export function getCouponRecord(data) {
  return request({
    url: '/api/app/coupon-record/get-all',
    method: 'post',
    baseURL: public_config.labor_api,
    data
  })
}

/**
 * 按ID查询优惠券
 * @param {*} id
 * @returns
 */
export function getByIdCouponRecord(id) {
  return request({
    url: `/api/app/coupon-record/${id}`,
    method: 'get',
    baseURL: public_config.labor_api
  })
}

export function deleteCouponRecord(data) {
  let json = ``
  data.forEach((item, index) => {
    console.log(item)
    if (index == 0) {
      json = `?ids=${item.id}`
    } else if (index > 0) {
      json += `&ids=${item.id}`
    }
  })
  return request({
    url: '/api/app/coupon-record/' + json,
    method: 'delete',
    baseURL: public_config.labor_api
  })
}

export function doEnabledCoupon(data) {
  return request({
    url: '/api/app/coupon/do-enabled',
    method: 'post',
    data
  })
}

export function insertCouponRecord(data) {
  return request({
    url: '/api/app/coupon-record/do-add',
    method: 'post',
    baseURL: public_config.labor_api,
    cancelErrorReject: true,
    data
  })
}

export function updateCouponRecord(data) {
  return request({
    url: '/api/app/coupon-record/do-update',
    method: 'post',
    baseURL: public_config.labor_api,
    data
  })
}

export function validParams(data) {
  return request({
    url: `/api/app/coupon-record/valid-params`,
    method: 'post',
    baseURL: public_config.labor_api,
    data
  })
}
